/**
 * @param {number[]} nums
 * @return {number}
 */
var longestConsecutive = function (nums) {
  const newSet = new Set(nums)
  let maxLength = 0

  for (let num of newSet) {
    if (!newSet.has(num - 1)) {
      let currentLength = 1
      let currentNum = num

      while (newSet.has(currentNum + 1)) {
        currentLength++
        currentNum++
      }

      maxLength = Math.max(maxLength, currentLength)
    }
  }

  return maxLength
};
console.log(longestConsecutive([0, 3, 7, 2, 5, 8, 4, 6, 0, 1]))